package com.gopay.bis.dao.bankorder.impl;

import com.gopay.bis.dao.bankorder.BisBankRspCodeFeatureDao;
import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.domain.bank.bcdl.BisBankRspCodeFeature;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zyt on 2017/9/22.
 */
@Repository(value = "bisBankRspCodeFeatureDao")
public class BisBankRspCodeFeatureDaoImpl extends BaseDAOImpl<BisBankRspCodeFeature, String>
        implements BisBankRspCodeFeatureDao {

    @Override
    public BisBankRspCodeFeature findByInfos(String bankCode, String transType, String returnCode, String dealResult){
        String hql = "from BisBankRspCodeFeature where bankCode = :bankCode and transCode = :transCode and returnCode = :returnCode";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("bankCode", bankCode);
        params.put("transType", transType);
        params.put("returnCode", returnCode);
        if(StringUtils.isNotBlank(dealResult)){
            hql = hql + " and dealResult = :dealResult";
            params.put("dealResult", dealResult);
        } else {
            hql = hql + " and dealResult is null";
        }

        List<BisBankRspCodeFeature> bisBankRspCodeList = this.findByHql(hql, params);
        if(bisBankRspCodeList != null && bisBankRspCodeList.size() > 0){
            return bisBankRspCodeList.get(0);
        }
        return null;
    }

    @Override
    public List<BisBankRspCodeFeature> findAll() {
        String hql = "from BisBankRspCodeFeature where 1=1 ";
        return this.findByHql(hql);
    }
}
